<?php
/**
 * 同步基础信息
 * User: allen_ios
 * Date: 16/11/24
 * Time: 上午11:53
 */

namespace Task\App\Doorbjhq;
use Task\Core\Base;
use Task\Core\RedisQueueService;


class SyncDoorbjhq extends Base
{
    protected $mysql;
    protected $mysqli;

    public function __construct()
    {
        parent::__construct();
        $this->mysql = $this->selectDB('mysql');
    }


    public function aa(){

//        $result = M('Building') -> where(array('account_id'=>params)) -> find();
 /*       $sql = "select building_id from gc_building where account_id = 60 and cut_off = 0";
        $result = $this->mysql->query($sql)->fetchAll();
cdump($result);*/
        /*$sql = 'insert into `gc_repaireast_canshu` (`canshu`,`canshu2`,`canshu3`) values (1,2,3)';
        echo $sql;
        $this->mysql->query($sql);
        $res = $this->mysql->error();
        cdump($res);*/

        $sql = 'insert into `gc_repaireast_canshu` (`canshu`,`canshu2`,`canshu3`) values (1,2,3)';
        $this->mysql->query($sql);
        //第一种
        $sql1 = "select last_insert_id() as sid";
        //第二种
//        $sql1 = 'select max(can_id) as id from gc_repaireast_canshu';

        $ss = $this->mysql->query($sql1)->fetch(\PDO::FETCH_ASSOC);

        cdump($ss['sid']);

    }

    /**
     * 手动同步到平治楼幢信息
     * @param $account_id
     */
    public function getBuildList($account_id){
        $sql = "select b.building_id,b.community_id,b.building_name,a.community_name from gc_building as b join gc_community as a on a.community_id = b.community_id  where b.account_id = ".$account_id." and b.cut_off = 0";
        $result = $this->mysql->query($sql)->fetchAll(\PDO::FETCH_ASSOC);

        $doorctrlBjhqApi = new DoorctrlBjhqApi();

        $functionName = 'AddUpdateDepart';
        foreach($result as $k=>$v) {
            $params = array(
                'depart' => array('departName' => $v['community_name'].$v['building_name'], 'outID' => $v['building_id'], 'fartherOutID' => $v['community_id'])
            );

            try{
                $aa = $doorctrlBjhqApi :: callApi($functionName, $params);
            }catch (\Exception $e) {
                $msg = $e->getMessage();
//                error_log("ms:{json_encode($msg)}",3,"/mnt/tasklog/pullTaskData.log");
            }

//            cdump(json_encode($aa).$v['building_name']);
//            cdump(json_encode($params));exit;

        }

    }

}